from django.shortcuts import redirect
from myShop.settings import AUTH_LIST

#自定义的中间件
class Auth(object):
    def __init__(self,get_response):
        self.get_response = get_response

    def __call__(self, request,*args, **kwargs):
        print(request.path)
        #判断当前的路由是不是只有登录后才能访问
        if request.path in AUTH_LIST:
            if not request.session.get('user'):
                return redirect('/user/login')
        return self.get_response(request, *args, **kwargs)
